<?php
/**
 * 描述
 * Created by Paco
 * Date: 2018/8/15 Time: 10:40
 */

namespace App\Http\Controllers\Admin\Auth;


use App\Http\Controllers\Controller;
use App\Http\Request\Auth\AdminStore;
use App\Http\Request\Auth\LoginStore;
use App\Repositories\Auth\AdminRepository;
use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Log;

class LoginController extends Controller
{
    private $admin;

    public function __construct(AdminRepository $admin)
    {
        $this->admin = $admin;
    }

    /**
     *
     * 描述
     * Created by Paco
     * Date: 2018/8/15
     * Time: 22:51
     * @param LoginStore $login
     * @param Request $request
     * @return mixed
     * @throws \Illuminate\Validation\ValidationException
     */
    public function login(LoginStore $login, Request $request)
    {
        $params = $login->validated($request);
        $ip = $request->getClientIp();
        return $this->admin->login($params['username'], $params['password'], $ip, $params['force'] ?? 0);
    }

    /**
     *
     * 注册
     * @author Paco
     * @createTime 2018/8/22 10:45
     * @param AdminStore $admin
     * @param Request $request
     * @return mixed
     * @throws \Illuminate\Validation\ValidationException
     */
    public function register(AdminStore $admin, Request $request)
    {
        $params = $admin->validated($request);
        return $this->admin->store($params);
    }


    public function info()
    {
        return $this->admin->info();
    }

    /**
     *
     * loginout
     * author Paco
     * createTime 2019/2/2 10:28
     * @return mixed
     * @throws \Exception
     */
    public function loginout()
    {
        return $this->admin->loginOut();
    }

}